package com.sky.controller.admin;

import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Category;
import com.sky.result.Result;
import com.sky.service.DishService;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/dish")
public class DishController {
    @Autowired
    DishService dishService;

    //新增产品
    @PostMapping
    public Result addDish(@RequestBody DishDTO dishDTO){
        return dishService.addDish(dishDTO);
    }

    @GetMapping("/page")
    public Result page(DishPageQueryDTO pageQueryDTO){

       return dishService.page(pageQueryDTO);

    }
    //根据id批量删除
    @DeleteMapping
    public Result DropByIds(@RequestParam List<Long> ids){
        return dishService.DropByIds(ids);
    }

    @GetMapping("/{id}")
    public Result GetById(@PathVariable Long id){
        return dishService.GetById(id);
    }
    @PutMapping
    public Result Update(@RequestBody DishDTO dishDTO){
        Result update = dishService.Update(dishDTO);
        return update;
    }

    @GetMapping("/list")
    public Result getByCategoryId(Long categoryId){
        return dishService.getByCategoryId(categoryId);
    }

}
